package thread;

public class Wait {
    private boolean isDone = false;
    public synchronized void test(int a)throws Exception{
        System.out.println(a);
        int i=0;
        while (true) {
            System.out.println(a+":"+(i++));
            if (i == 1000) {
                this.wait();
            }
            if (i == 2000) {
                break;
            }

        }

    }
    public synchronized void test2(int a)throws Exception{
        System.out.println(a);
        int i=0;
        while (true) {
            System.out.println(a+":"+(i--));
            if (i == -1000) {
                this.wait();
            }
            if (i == -2000) {
                break;
            }

        }

    }
    public synchronized void test1(int a)throws Exception{
        this.notifyAll();
        System.out.println("ok.....ebd");

    }
    public static void main(String[] args) throws InterruptedException {
        Wait wait = new Wait();
        Thread t = new Thread(() -> {
            try {
                wait.test(11);
            } catch (Exception e) {
                e.printStackTrace();
            }
        });
        Thread t3 = new Thread(() -> {
            try {
                wait.test2(11);
            } catch (Exception e) {
                e.printStackTrace();
            }
        });
        Thread t1 = new Thread(() -> {
            try {
                Thread.currentThread().sleep(5000);
                System.out.println("ok.....");
                wait.test1(12);
            } catch (Exception e) {
                e.printStackTrace();
            }
        });
        t.start();
        t3.start();
        t1.start();
    }
}
